package algo_lignes_sites.data.force;

import commons.ihm.ParametresAffichageCarto;
import commons.drawing.SegmentDrawable;
import java.awt.Color;
import commons.utils.primitive_geom.Point_d;
import java.awt.Graphics2D;


public class ForceDrawable extends SegmentDrawable {

	// rouge
	public static Color COLOR_COMPOSANTE_REPULS = new Color(255, 200, 200);
	public static Color COLOR_RESULTANTE_REPULS = new Color(255, 0, 0);

	public static Color COLOR_COMPOSANTE_ATTRACTPOS = new Color(200, 255, 200);
	public static Color COLOR_RESULTANTE_ATTRACTPOS = new Color(0, 190, 0);

	// fushia
	public static Color COLOR_COMPOSANTE_ENTRAINEMENT = new Color(200, 150, 200);
	public static Color COLOR_RESULTANTE_ENTRAINEMENT = new Color(200, 0, 200);

	// bleu
	public static Color COLOR_COMPOSANTE_FORME = new Color(200, 200, 255);
	public static Color COLOR_RESULTANTE_FORME = new Color(0, 0, 255);


	Point_d ptDepart;
	Force force;

	public ForceDrawable(Point_d ptDepart, Force force, float width_px, Color color) {
		super (color, -1, width_px);
		this.ptDepart = ptDepart;
		this.force = force;
	}


	//**************************************************************************
	// IDrawable
	//**************************************************************************
	
	// On met a jour les coordonnées du segment (super) et on appelle super.draw()
	@Override
	public void draw(Graphics2D g, ParametresAffichageCarto pac) {

		// si la force est un minuscule segment, on ne l'affiche pas sinon ca pollue un peu l'affichage avec des points
		if (pac.lg2LG(Math.abs(force.dx))<0.5 && pac.lg2LG(Math.abs(force.dy))<0.5)
			return;
		
		majCoordSegment();
		super.draw(g, pac);
	}

	private void majCoordSegment() {
		pt1.x = ptDepart.x;
		pt1.y = ptDepart.y;
		pt2.x = ptDepart.x + force.dx;
		pt2.y = ptDepart.y + force.dy;
	}

	@Override
	public double distTo(Point_d pt) {
		majCoordSegment();
		return super.distTo(pt);
	}

	@Override
	public String toString() {return getInfoBulle();}

	@Override
	public String getInfoBulle() {
		return "Force";
	}

	@Override
	public String getInfoDetaillee() {
		String res = "Force de longueur " + Math.sqrt(force.dx*force.dx + force.dy*force.dy);

		return res;
	}
}
